package com.turman.course

import androidx.lifecycle.LiveData
import androidx.lifecycle.liveData
import com.turman.course.model.Girl
import com.turman.course.model.ResponseBean
import kotlinx.coroutines.Dispatchers
import java.lang.Exception

class ApiHelper(private val apiService: ApiService) {
    fun getGirls(page:Int):LiveData<NetResult<ResponseBean<Girl>>> = liveData(Dispatchers.IO) {
        emit(NetResult.loading(null))
        try {
            emit(NetResult.success(apiService.getGirls(page)))
        } catch (e: Exception) {
            emit(NetResult.error(e.message, null))
        }
    }
}